#!/usr/bin/env python
# -*- coding: utf-8 -*-


import requests
import re
import sys


reload(sys)
sys.setdefaultencoding('UTF-8')


def Show_Weather(city):
    res = str(city).split('" title="')
    print res[1], '(白天-->夜间)'
    html = requests.get("http://www.tianqihoubao.com/weather/{0}".format(res[0]))
    weather = re.search('<table width="100%" border="0" class="b" cellpadding="1" cellspacing="1">(.*?)</table>', html.text,re.S).group(1)
    res = re.findall('<tr>(.*?)</tr>',weather,re.S)

    for x in res[2:]:
        w = re.findall('>(.*?)<',x,re.S)
        for y in w[1:]:
            if len(y.strip())<=0:
                pass
            else:
                print y

        print '--'*40
    print '\n','*'*40


def show_city():
    html = requests.get("http://www.tianqihoubao.com/weather/province.aspx?id=440000")
    citys = re.findall('<td style="height: 22px" align="center"><a href="(.*?)">', html.text,re.S)
    for city in citys:
        Show_Weather(city)

def main():
    show_city()


if __name__ == '__main__':
    main()


